package com.yatuhashi.encrypt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.yatuhashi.encrypt.R;
import com.yatuhashi.encrypt.bean.ViewHolder;

public class BaseAdapter extends ArrayAdapter<String>{
	private LayoutInflater mLayoutInflater;
	
	public BaseAdapter(Context context) {
		super(context, 0);
		mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		String title = getItem(position);
		
		if(convertView==null) {
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.row_list, null);
			holder.setTextView((TextView) convertView.findViewById(R.id.row_title));
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		TextView textView = (TextView)convertView.findViewById(R.id.row_title);
		textView.setText(title);
		
		holder.setTextView(textView);
		
		return convertView;
	}
}
